<?php 
class cls_data_order extends cls_data_base
{
	function check_if_related_data($customerid, $orderid)
	{
		$table_name = '`orders`';
	
		$sql = "select * from {$table_name} where CustomerID = {$customerid} and ID = {$orderid}";
		$result = $this->db->query($sql);
		$rows = $this->db->num_rows($result);
	
		if(!$rows)
		{
			return false;
		}
		elseif ($rows != 1)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	
	function get_all_order($customerid)
	{
		$table_name = '`orders`';
		//$address_table_name = '`address`';
	
		$sql = "select {$table_name}.ID, {$table_name}.OrderTime, {$table_name}.TotalPrice, {$table_name}.OrderState, {$table_name}.Receiver, {$table_name}.Address, {$table_name}.Postal, {$table_name}.Phone from {$table_name} where{$table_name}.CustomerID = {$customerid}";
		$result = $this->db->getAll($sql);
	
		return $result;
	}
	
	function get_order_detail($orderid)
	{
		$table_name = '`orderitem`';
		$product_table_name = '`product`';
	
		$sql = "select {$table_name}.ProductID, {$table_name}.ProductName, {$table_name}.Amount, {$table_name}.TotalPrice, {$product_table_name}.IMAGE, {$product_table_name}.Author from {$table_name},{$product_table_name} where OrderID = {$orderid} and {$table_name}.ProductID = {$product_table_name}.ID";
		$result = $this->db->getAll($sql);
	
		return $result;
	}
	
	function get_order_by_date_range($customerid, $start_time, $end_time)
	{
		$table_name = '`orders`';
		//$address_table_name = '`address`';
	
		$sql = "select {$table_name}.ID, {$table_name}.OrderTime, {$table_name}.TotalPrice, {$table_name}.OrderState, {$table_name}.Receiver, {$table_name}.Address, {$table_name}.Postal, {$table_name}.Phone from {$table_name} where{$table_name}.CustomerID = {$customerid} and {$table_name}.OrderTime between '{$start_time}' and '{$end_time}'";
		$result = $this->db->getAll($sql);
	
		return $result;
	}
}
?>